<?php
class Pageley_Domain_Attribute_Basic implements Pageley_Domain_Attribute {
	private $name;
	private $validators;

	public function __construct($name, $validators = null) {
		if($validators === null) {
			$validators = new Pageley_Util_ArrayMap();
		}
		$this->name = $name;
		$this->validators = $validators;
	}

	public function addValidator($validator) {
		$this->validators->add($validator);
	}

	public function getName() {
		return $this->name;
	}

	public function validate($value, $propertyName, $target) {
		if($this->validators != null) {
			$errors = new Pageley_Util_ArrayMap();
			foreach($this->validators as $validator) {
				$error = $validator->validate($value, $propertyName, $target);
				if($error != null) {
					$errors->putAll($error);
				}
			}
			if($errors->size() > 0) {
				throw new Pageley_Domain_Validator_Exception($errors);
			}
		}
	}

	public function isMultiple() {
		return false;
	}

	public function isReference() {
		return false;
	}

    public function isComposite() {
    	return false;
    }

    public function shouldEncrypt() {
    	return false;
    }

	public function newProperty() {
		return new Pageley_Domain_ValueProperty();
	}
	
	public function __toString() {
		return $this->getName();
	}
    
    public function getType() {
        return null;
    }
}